package calculate;

import java.util.Arrays;

public class MaoPao {

	public static void main(String[] args) {
		int[] is = {1,2,3,4,5};
		System.out.println(binarySearch(is,4));

	}

	public static int binarySearch(int[] srcArray, int des) {

		int low = 0;
		int high = srcArray.length - 1;
		while (low <= high) {
			int middle = (low + high) / 2;
			if (des == srcArray[middle]) {
				return middle;
			} else if (des < srcArray[middle]) {
				high = middle - 1;
			} else {
				low = middle + 1;
			}
		}
		return -1;
	}

	public static void t1(int[] is) {
		for (int i = 0; i < is.length; i++) {
			for (int j = i + 1; j < is.length; j++) {
				if (is[i] > is[j]) {
					int temp = is[i];
					is[i] = is[j];
					is[j] = temp;
					System.out.println(Arrays.toString(is));
				}
			}
		}
		System.out.println(Arrays.toString(is));
	}

}
